﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using BathhouseService.Models.SqlModels;


namespace BathhouseService.CURD.ViewModels.NoticeVMs
{
    public partial class NoticeListVM : BasePagedListVM<Notice_View, NoticeSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.Create, "新建","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.Edit, "修改","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.Delete, "删除", "CURD",dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.Details, "详细","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.BatchEdit, "批量修改","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.BatchDelete, "批量删除","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.Import, "导入","CURD", dialogWidth: 800),
                this.MakeStandardAction("Notice", GridActionStandardTypesEnum.ExportExcel, "导出","CURD"),
            };
        }

        protected override IEnumerable<IGridColumn<Notice_View>> InitGridHeader()
        {
            return new List<GridColumn<Notice_View>>{
                this.MakeGridHeader(x => x.Title),
                this.MakeGridHeader(x => x.Content),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<Notice_View> GetSearchQuery()
        {
            var query = DC.Set<Notice>()
                .CheckContain(Searcher.Title, x=>x.Title)
                .Select(x => new Notice_View
                {
				    ID = x.ID,
                    Title = x.Title,
                    Content = x.Content,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class Notice_View : Notice{

    }
}
